package com.myrabbitmqdemo.demo.two;


import com.myrabbitmqdemo.demo.utils.RabbitMqUtils;
import com.rabbitmq.client.CancelCallback;
import com.rabbitmq.client.Channel;
import com.rabbitmq.client.DeliverCallback;

import java.io.IOException;
import java.util.concurrent.TimeoutException;

/**
 *
 * @author zpf
 * 这个是个工作线程(消费者)
 *
 */
public class Worker01 {

    // 队列的名称
    public static final String QUEUE_NAME = "hello";

    public static void main(String[] args) throws IOException, TimeoutException {

        Channel channel = RabbitMqUtils.getChannel();

        DeliverCallback deliverCallback = (consumerTag,message) -> {
            System.out.println("接收到相关的信息："+new String(message.getBody()));
        };

        CancelCallback cancelCallback = (consumerTag)-> {
            System.out.println(consumerTag+":该条接口去掉消费者接口回调逻辑");
        };

        System.out.println("C2等待接收消息......");
        channel.basicConsume(QUEUE_NAME,true,deliverCallback,cancelCallback);
    }
}
